﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using lineage2.commons.lang.reference;

namespace Game.model.actor.instances.player
{
    public class Mentee
    {
        private int _objectId;
	    private String _name;
	    private int _classId;
	    private int _level;
	    private bool _isMentor;
	    private HardReference _playerRef = HardReferences.emptyRef();
        public Mentee(int objectId, String name, int classId, int level, bool isMentor)
        {
            _objectId = objectId;
            _name = name;
            _classId = classId;
            _level = level;
            _isMentor = isMentor;
        }
        public Mentee(Player player)
        {
            _objectId = player.getObjectId();
            update(player, true);
        }
        public Mentee(Player player, bool isMentor)
        {
            _objectId = player.getObjectId();
            _isMentor = isMentor;
            update(player, true);
        }
        public void update(Player player, bool set)
	    {
		    _level = player.getLevel();
		    _name = player.getName();
		    _classId = player.getActiveClassId();
		    _playerRef = set ? player.getRef() : HardReferences.emptyRef();
	    }
        public String getName()
        {
            Player player = getPlayer();
            return player == null ? _name : player.getName();
        }
        public int getObjectId()
        {
            return _objectId;
        }
        public int getClassId()
        {
            Player player = getPlayer();
            return player == null ? _classId : player.getActiveClassId();
        }
        public int getLevel()
        {
            Player player = getPlayer();
            return player == null ? _level : player.getLevel();
        }
        public bool isOnline()
        {
            var player = (Player) _playerRef.get();
            return (player != null) && !player.isInOfflineMode();
        }
        public Player getPlayer()
        {
            var player = (Player) _playerRef.get();
            return (player != null) && !player.isInOfflineMode() ? player : null;
        }
        public bool isMentor()
        {
            return _isMentor;
        }
    }
}
